<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"><title>SpringBoot集成支付宝沙箱支付 | 飞の博客</title><meta name="author" content="Fei"><meta name="copyright" content="Fei"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="ffffff"><meta name="description" content="SpringBoot集成Knife4j接口文档">
<meta property="og:type" content="article">
<meta property="og:title" content="SpringBoot集成支付宝沙箱支付">
<meta property="og:url" content="https://tengfei2233.gitee.io/2023/2/27/SpringBoot%E9%9B%86%E6%88%90%E6%94%AF%E4%BB%98%E5%AE%9D%E6%B2%99%E7%AE%B1%E6%94%AF%E4%BB%98/index.html">
<meta property="og:site_name" content="飞の博客">
<meta property="og:description" content="SpringBoot集成Knife4j接口文档">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-3-2/alipay.jpg">
<meta property="article:published_time" content="2023-02-27T02:11:54.000Z">
<meta property="article:modified_time" content="2023-02-27T02:11:54.000Z">
<meta property="article:author" content="Fei">
<meta property="article:tag" content="Java">
<meta property="article:tag" content="SpringBoot">
<meta property="article:tag" content="支付宝沙箱支付">
<meta property="article:tag" content="在线支付">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-3-2/alipay.jpg"><link rel="shortcut icon" href="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/common/icon.png"><link rel="canonical" href="https://tengfei2233.gitee.io/2023/2/27/SpringBoot%E9%9B%86%E6%88%90%E6%94%AF%E4%BB%98%E5%AE%9D%E6%B2%99%E7%AE%B1%E6%94%AF%E4%BB%98/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//hm.baidu.com"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta name="msvalidate.01" content="2ADFA30867CBC6E090E3C5B244DC311D"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.3.0/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.staticfile.org/fancyapps-ui/4.0.31/fancybox.min.css" media="print" onload="this.media='all'"><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?07a1f58fb95d3d4a97c2ae0a181c9964";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":200},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.staticfile.org/flickr-justified-gallery/2.1.2/fjGallery.min.js',
      css: 'https://cdn.staticfile.org/flickr-justified-gallery/2.1.2/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: true,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'SpringBoot集成支付宝沙箱支付',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-02-27 10:11:54'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', 'ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>const preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',()=> { preloader.endLoading() })

if (false) {
  document.addEventListener('pjax:send', () => { preloader.initLoading() })
  document.addEventListener('pjax:complete', () => { preloader.endLoading() })
}</script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/common/fei.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">24</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">28</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">16</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" target="_blank" rel="noopener" href="https://github.com/tengfei2233"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-3-2/alipay.jpg')"><nav id="nav"><span id="blog-info"><a href="/" title="飞の博客"><span class="site-name">飞の博客</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" target="_blank" rel="noopener" href="https://github.com/tengfei2233"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">SpringBoot集成支付宝沙箱支付</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-02-27T02:11:54.000Z" title="发表于 2023-02-27 10:11:54">2023-02-27</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-02-27T02:11:54.000Z" title="更新于 2023-02-27 10:11:54">2023-02-27</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Java/">Java</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Java/SpringBoot/">SpringBoot</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">1.5k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>6分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="SpringBoot集成支付宝沙箱支付"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="SpringBoot集成支付宝沙箱支付"><a href="#SpringBoot集成支付宝沙箱支付" class="headerlink" title="SpringBoot集成支付宝沙箱支付"></a>SpringBoot集成支付宝沙箱支付</h2><blockquote>
<p>个人账号未申请上架的App&#x2F;网站是无法接入支付宝支付的，但是可以使用支付宝沙箱版进行练手。沙箱版就相当于不不涉及现实金额交易的一个支付宝模拟环境，其中交易的金额都是虚假的内容。</p>
</blockquote>
<h3 id="准备步骤"><a href="#准备步骤" class="headerlink" title="准备步骤"></a>准备步骤</h3><ul>
<li><p>进入支付包开放平台找到沙箱应用管理平台-&gt; <a target="_blank" rel="noopener" href="https://open.alipay.com/develop/sandbox/app">地址</a></p>
</li>
<li><p>创建沙箱应用，之后界面如下</p>
</li>
<li><p><img src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-3-2/%E6%94%AF%E4%BB%98%E5%AE%9D%E6%B2%99%E7%AE%B1%E7%95%8C%E9%9D%A2.png"></p>
</li>
<li><p>在基本信息栏，开发信息中选择：自定义密钥</p>
</li>
<li><p>公钥模式：设置并查看</p>
</li>
<li><p>使用支付宝密钥生成工具或openssl工具生成公私钥，将公钥复制到加签内容配置内，结果如下</p>
</li>
<li><p><img src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-3-2/%E5%85%AC%E7%A7%81%E9%92%A5.png"></p>
</li>
<li><p><strong>以上开发平台配置部分就完成了</strong></p>
</li>
</ul>
<h3 id="接入SpringBoot"><a href="#接入SpringBoot" class="headerlink" title="接入SpringBoot"></a>接入SpringBoot</h3><h4 id="SpringBoot版本"><a href="#SpringBoot版本" class="headerlink" title="SpringBoot版本"></a>SpringBoot版本</h4><figure class="highlight xml"><table><tr><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">parent</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-parent<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>2.4.12<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">relativePath</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">parent</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h4 id="依赖版本"><a href="#依赖版本" class="headerlink" title="依赖版本"></a>依赖版本</h4><figure class="highlight xml"><table><tr><td class="code"><pre><span class="line"> <span class="comment">&lt;!-- springboot --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-web<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"> <span class="comment">&lt;!-- 支付宝模拟支付SDK --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.alipay.sdk<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>alipay-sdk-java<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>4.16.2.ALL<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- lombok --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.projectlombok<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>lombok<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h4 id="在resources目录编写alipay-properties配置文件"><a href="#在resources目录编写alipay-properties配置文件" class="headerlink" title="在resources目录编写alipay.properties配置文件"></a>在resources目录编写alipay.properties配置文件</h4><figure class="highlight properties"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 支付宝</span></span><br><span class="line"><span class="comment"># appId</span></span><br><span class="line"><span class="attr">alipay.appId</span>=<span class="string">你的appid</span></span><br><span class="line"><span class="comment"># 应用私钥</span></span><br><span class="line"><span class="attr">alipay.appPrivateKey</span>=<span class="string">你的应用私钥，在C:\Users\用户名\Documents\支付宝开放平台密钥工具\日期（前提是你用的支付宝工具生成的公私钥）</span></span><br><span class="line"><span class="comment"># 支付宝公钥</span></span><br><span class="line"><span class="attr">alipay.alipayPublicKey</span>=<span class="string">你的支付宝公钥，在支付宝沙箱管理平台</span></span><br><span class="line"><span class="comment"># 异步回调一般用于数据持久化</span></span><br><span class="line"><span class="comment"># 异步回调地址（主要是用于支付完成后异步回调的地址，必须是公网（可以使用内网穿透））</span></span><br><span class="line"><span class="attr">alipay.notifyUrl</span>=<span class="string">http://xxxx.xxx/xxx</span></span><br><span class="line"><span class="comment"># 同步回调一般用于页面跳转</span></span><br><span class="line"><span class="comment"># 同步回调地址（主要是用于支付完成后同步回调地址，可以是本地地址）</span></span><br><span class="line"><span class="attr">alipay.returnUrl</span>=<span class="string">http://xxxx.xxx/xxx</span></span><br><span class="line"><span class="comment"># 支付宝网关地址（沙箱版，非沙箱版需要修改）</span></span><br><span class="line"><span class="attr">alipay.gatewayUrl</span>=<span class="string">https://openapi.alipaydev.com/gateway.do</span></span><br><span class="line"><span class="comment"># 加密方式：默认</span></span><br><span class="line"><span class="attr">alipay.signType</span>=<span class="string">RSA2</span></span><br><span class="line"><span class="comment"># 支付成功重定向地址（非支付宝配置，此处是支付完成后跳转的页面地址，根据需求添加删除）</span></span><br><span class="line"><span class="attr">alipay.redirectUrl</span>=<span class="string">http://xxxx.xxx/xxx</span></span><br></pre></td></tr></table></figure>

<h4 id="编写AlipayConfig-java用于读取配置文件"><a href="#编写AlipayConfig-java用于读取配置文件" class="headerlink" title="编写AlipayConfig.java用于读取配置文件"></a>编写AlipayConfig.java用于读取配置文件</h4><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="meta">@PropertySource(&quot;classpath:alipay.properties&quot;)</span></span><br><span class="line"><span class="meta">@ConfigurationProperties(prefix = &quot;alipay&quot;)</span></span><br><span class="line"><span class="meta">@Data</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">AlipayConfig</span> &#123;</span><br><span class="line">    <span class="comment">// appId</span></span><br><span class="line">    <span class="keyword">private</span> String appId;</span><br><span class="line">    <span class="comment">// 应用私钥</span></span><br><span class="line">    <span class="keyword">private</span> String appPrivateKey;</span><br><span class="line">    <span class="comment">// 支付宝公钥</span></span><br><span class="line">    <span class="keyword">private</span> String alipayPublicKey;</span><br><span class="line">    <span class="comment">// 异步回调地址（主要是用于支付完成后执行数据持久化（必须是公网ip））</span></span><br><span class="line">    <span class="keyword">private</span> String notifyUrl;</span><br><span class="line">    <span class="comment">// 同步回调地址（主要是用于支付完成后的页面跳转（可以是本地地址））</span></span><br><span class="line">    <span class="keyword">private</span> String returnUrl;</span><br><span class="line">    <span class="comment">// 支付宝网关地址</span></span><br><span class="line">    <span class="keyword">private</span> String gatewayUrl;</span><br><span class="line">    <span class="comment">// 加密方式</span></span><br><span class="line">    <span class="keyword">private</span> String signType;</span><br><span class="line">    <span class="comment">// 支付成功重定向地址</span></span><br><span class="line">    <span class="keyword">private</span> String redirectUrl;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="在需要支付的方法上调用如下方法"><a href="#在需要支付的方法上调用如下方法" class="headerlink" title="在需要支付的方法上调用如下方法"></a>在需要支付的方法上调用如下方法</h4><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line"><span class="comment">// 在使用这个方法前需要注入以下bean</span></span><br><span class="line"><span class="comment">// 支付宝配置文件</span></span><br><span class="line"><span class="meta">@Resource</span></span><br><span class="line"><span class="keyword">private</span> AlipayConfig alipayConfig;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 付款</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> outTradeNo	订单ID（自定义生成，在调用方法前生成）</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> totalAmount	订单金额</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> subject		订单描述</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line"><span class="keyword">private</span> String <span class="title function_">sendRequestToAlipay</span><span class="params">(String outTradeNo, String totalAmount, String subject)</span> &#123;</span><br><span class="line">    <span class="comment">//获得初始化的AlipayClient</span></span><br><span class="line">    <span class="type">AlipayClient</span> <span class="variable">alipayClient</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">DefaultAlipayClient</span>(alipayConfig.getGatewayUrl(), alipayConfig.getAppId(), alipayConfig.getAppPrivateKey(),</span><br><span class="line">                                                        <span class="string">&quot;JSON&quot;</span>, <span class="string">&quot;UTF-8&quot;</span>, alipayConfig.getAlipayPublicKey(), alipayConfig.getSignType());</span><br><span class="line"></span><br><span class="line">    <span class="comment">//设置请求参数</span></span><br><span class="line">    <span class="type">AlipayTradePagePayRequest</span> <span class="variable">alipayRequest</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">AlipayTradePagePayRequest</span>();</span><br><span class="line">    alipayRequest.setReturnUrl(alipayConfig.getReturnUrl());</span><br><span class="line">    alipayRequest.setNotifyUrl(alipayConfig.getNotifyUrl());</span><br><span class="line">	<span class="comment">// 默认写法，不可更改</span></span><br><span class="line">    alipayRequest.setBizContent(<span class="string">&quot;&#123;\&quot;out_trade_no\&quot;:\&quot;&quot;</span> + outTradeNo + <span class="string">&quot;\&quot;,&quot;</span></span><br><span class="line">                                + <span class="string">&quot;\&quot;total_amount\&quot;:\&quot;&quot;</span> + totalAmount + <span class="string">&quot;\&quot;,&quot;</span></span><br><span class="line">                                + <span class="string">&quot;\&quot;subject\&quot;:\&quot;&quot;</span> + subject + <span class="string">&quot;\&quot;,&quot;</span></span><br><span class="line">                                + <span class="string">&quot;\&quot;product_code\&quot;:\&quot;FAST_INSTANT_TRADE_PAY\&quot;&#125;&quot;</span>);</span><br><span class="line"></span><br><span class="line">    <span class="comment">//请求</span></span><br><span class="line">    <span class="type">String</span> <span class="variable">result</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        result = alipayClient.pageExecute(alipayRequest).getBody();</span><br><span class="line">    &#125; <span class="keyword">catch</span> (AlipayApiException e) &#123;</span><br><span class="line">        e.printStackTrace();</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 返回响应体</span></span><br><span class="line">    <span class="keyword">return</span> result;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="异步回调"><a href="#异步回调" class="headerlink" title="异步回调"></a>异步回调</h4><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">// Controller</span></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 付款成功异步回调，将数据持久化到数据库</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> request</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> AlipayApiException</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line"><span class="meta">@ApiOperation(&quot;付款成功异步回调&quot;)</span></span><br><span class="line"><span class="meta">@PostMapping(&quot;asyncNotify&quot;)</span></span><br><span class="line"><span class="keyword">public</span> String <span class="title function_">notifyUrl</span><span class="params">(HttpServletRequest request)</span> <span class="keyword">throws</span> AlipayApiException &#123;</span><br><span class="line">    <span class="keyword">return</span> orderService.notifyUrl(request);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">// Service</span></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 异步回调</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> request</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> UnsupportedEncodingException</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> AlipayApiException</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line"><span class="keyword">public</span> String <span class="title function_">notifyUrl</span><span class="params">(HttpServletRequest request)</span> <span class="keyword">throws</span> AlipayApiException &#123;</span><br><span class="line">    logger.info(<span class="string">&quot;=================================异步回调=====================================&quot;</span>);</span><br><span class="line">    <span class="comment">// 获取支付宝GET过来反馈信息</span></span><br><span class="line">    Map&lt;String, String&gt; params = <span class="keyword">new</span> <span class="title class_">HashMap</span>&lt;&gt;();</span><br><span class="line">    Map&lt;String, String[]&gt; requestParams = request.getParameterMap();</span><br><span class="line">    <span class="keyword">for</span> (String name : requestParams.keySet()) &#123;</span><br><span class="line">        params.put(name, request.getParameter(name));</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="type">boolean</span> <span class="variable">signVerified</span> <span class="operator">=</span> AlipaySignature.rsaCheckV1(params, alipayConfig.getAlipayPublicKey(), <span class="string">&quot;UTF-8&quot;</span>, alipayConfig.getSignType()); <span class="comment">// 调用SDK验证签名</span></span><br><span class="line">    <span class="comment">//验证签名通过</span></span><br><span class="line">    <span class="keyword">if</span> (signVerified) &#123;</span><br><span class="line">        logger.info(<span class="string">&quot;交易名称: &quot;</span> + params.get(<span class="string">&quot;subject&quot;</span>));</span><br><span class="line">        logger.info(<span class="string">&quot;交易状态: &quot;</span> + params.get(<span class="string">&quot;trade_status&quot;</span>));</span><br><span class="line">        logger.info(<span class="string">&quot;支付宝交易凭证号: &quot;</span> + params.get(<span class="string">&quot;trade_no&quot;</span>));</span><br><span class="line">        logger.info(<span class="string">&quot;商户订单号: &quot;</span> + params.get(<span class="string">&quot;out_trade_no&quot;</span>));</span><br><span class="line">        logger.info(<span class="string">&quot;交易金额: &quot;</span> + params.get(<span class="string">&quot;total_amount&quot;</span>));</span><br><span class="line">        logger.info(<span class="string">&quot;买家在支付宝唯一id: &quot;</span> + params.get(<span class="string">&quot;buyer_id&quot;</span>));</span><br><span class="line">        logger.info(<span class="string">&quot;买家付款时间: &quot;</span> + params.get(<span class="string">&quot;gmt_payment&quot;</span>));</span><br><span class="line">        logger.info(<span class="string">&quot;买家付款金额: &quot;</span> + params.get(<span class="string">&quot;buyer_pay_amount&quot;</span>));</span><br><span class="line">        logger.info(<span class="string">&quot;重定向URL: &quot;</span> + params.get(<span class="string">&quot;body&quot;</span>));</span><br><span class="line"></span><br><span class="line">        <span class="comment">// TODO 支付成功，修改数据库等信息</span></span><br><span class="line">        </span><br><span class="line">        <span class="type">Integer</span> <span class="variable">res</span> <span class="operator">=</span> orderMapper.toBuy(order);</span><br><span class="line">        <span class="keyword">if</span> (res &gt;= <span class="number">1</span>) &#123;</span><br><span class="line">            <span class="comment">//跳转付款成功页面</span></span><br><span class="line">            <span class="keyword">return</span> <span class="string">&quot;ok&quot;</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 支付宝失败退款</span></span><br><span class="line">        <span class="comment">//跳转付款失败页面</span></span><br><span class="line">        <span class="keyword">return</span> <span class="string">&quot;no&quot;</span>;</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="comment">//跳转付款失败页面</span></span><br><span class="line">        <span class="keyword">return</span> <span class="string">&quot;no&quot;</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="同步回调"><a href="#同步回调" class="headerlink" title="同步回调"></a>同步回调</h4><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">// Controller</span></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 付款成功同步回调，用户url重定向</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> request</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> response</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> IOException</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line"><span class="meta">@ApiOperation(&quot;付款成功同步回调&quot;)</span></span><br><span class="line"><span class="meta">@GetMapping(&quot;syncNotify&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">returnUrl</span><span class="params">(HttpServletRequest request, HttpServletResponse response)</span> <span class="keyword">throws</span> IOException &#123;</span><br><span class="line">    orderService.returnUrl(request, response);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// Service</span></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 同步回调</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> request</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> response</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> IOException</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">returnUrl</span><span class="params">(HttpServletRequest request, HttpServletResponse response)</span> <span class="keyword">throws</span> IOException &#123;</span><br><span class="line">    logger.info(<span class="string">&quot;=================================同步回调=====================================&quot;</span>);</span><br><span class="line">    <span class="comment">// TODO 进行相应的操作</span></span><br><span class="line">    </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="以上配置完后，点击支付url，跳转到支付宝沙箱扫码支付页面，使用：支付宝沙箱软件支付"><a href="#以上配置完后，点击支付url，跳转到支付宝沙箱扫码支付页面，使用：支付宝沙箱软件支付" class="headerlink" title="以上配置完后，点击支付url，跳转到支付宝沙箱扫码支付页面，使用：支付宝沙箱软件支付"></a>以上配置完后，点击支付url，跳转到支付宝沙箱扫码支付页面，使用：<a target="_blank" rel="noopener" href="https://open.alipay.com/develop/sandbox/tool/alipayclint">支付宝沙箱软件支付</a></h4><h4 id="登录账号密码："><a href="#登录账号密码：" class="headerlink" title="登录账号密码："></a>登录账号密码：</h4><p><img src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-3-2/%E6%B2%99%E7%AE%B1%E8%B4%A6%E5%8F%B7%E5%AF%86%E7%A0%81.png"></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://tengfei2233.gitee.io">Fei</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://tengfei2233.gitee.io/2023/2/27/SpringBoot%E9%9B%86%E6%88%90%E6%94%AF%E4%BB%98%E5%AE%9D%E6%B2%99%E7%AE%B1%E6%94%AF%E4%BB%98/">https://tengfei2233.gitee.io/2023/2/27/SpringBoot%E9%9B%86%E6%88%90%E6%94%AF%E4%BB%98%E5%AE%9D%E6%B2%99%E7%AE%B1%E6%94%AF%E4%BB%98/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://tengfei2233.gitee.io" target="_blank">飞の博客</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Java/">Java</a><a class="post-meta__tags" href="/tags/SpringBoot/">SpringBoot</a><a class="post-meta__tags" href="/tags/%E6%94%AF%E4%BB%98%E5%AE%9D%E6%B2%99%E7%AE%B1%E6%94%AF%E4%BB%98/">支付宝沙箱支付</a><a class="post-meta__tags" href="/tags/%E5%9C%A8%E7%BA%BF%E6%94%AF%E4%BB%98/">在线支付</a></div><div class="post_share"><div class="social-share" data-image="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-3-2/alipay.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.staticfile.org/butterfly-extsrc/1.1.3/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.staticfile.org/butterfly-extsrc/1.1.3/sharejs/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/common/wechat.png" target="_blank"><img class="post-qr-code-img" src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/common/wechat.png" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/common/alipay.png" target="_blank"><img class="post-qr-code-img" src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/common/alipay.png" alt="支付宝"/></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2023/2/12/SpringBoot%E9%9B%86%E6%88%90Redisson%E6%9B%BF%E6%8D%A2SpringCache%E5%BA%95%E5%B1%82%E5%AE%B9%E5%99%A8%E5%AE%9E%E7%8E%B0/" title="SpringBoot集成Redisson替换SpringCache底层容器实现"><img class="cover" src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-2-26/redisson.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">SpringBoot集成Redisson替换SpringCache底层容器实现</div></div></a></div><div class="next-post pull-right"><a href="/2023/3/2/Java%E8%B0%83%E7%94%A8Ffmpeg%E5%AE%9E%E7%8E%B0%E8%A7%86%E9%A2%91%E8%BD%ACM3U8/" title="Java集成Ffmpeg实现视频转M3U8"><img class="cover" src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-3-2/ffmpeg.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Java集成Ffmpeg实现视频转M3U8</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2023/11/21/netty%E7%9A%84%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8%EF%BC%8C%E5%9F%BA%E6%9C%AC%E5%8E%9F%E7%90%86%E5%88%86%E6%9E%90%EF%BC%8C%E7%9B%B8%E5%85%B3%E9%97%AE%E9%A2%98%E8%A7%A3%E5%86%B3-%E6%9B%B4%E6%96%B0%E4%B8%AD/" title="netty的基本使用，基本原理分析，相关问题解(更新中...)"><img class="cover" src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-11-10/netty-ai.png" alt="cover"><div class="content is-center"><div class="date"><i class="fas fa-history fa-fw"></i> 2023-11-21</div><div class="title">netty的基本使用，基本原理分析，相关问题解(更新中...)</div></div></a></div><div><a href="/2023/6/15/SpringBoot%E9%9B%86%E6%88%90SpringSecurity%E5%AE%9E%E7%8E%B0%E5%89%8D%E5%90%8E%E7%AB%AF%E5%88%86%E7%A6%BB%E6%9D%83%E9%99%90%E6%A0%A1%E9%AA%8C-%E6%96%B0%E7%89%88%E9%85%8D%E7%BD%AE%E6%96%B9%E5%BC%8F/" title="SpringBoot集成SpringSecurity实现前后端分离权限校验(新版配置方式)(待更新...)"><img class="cover" src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-15/security.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="fas fa-history fa-fw"></i> 2023-07-17</div><div class="title">SpringBoot集成SpringSecurity实现前后端分离权限校验(新版配置方式)(待更新...)</div></div></a></div><div><a href="/2023/6/15/Jackson%E8%A7%A3%E5%86%B3SpringMVC%E5%85%A8%E5%B1%80%E5%BA%8F%E5%88%97%E5%8C%96%E8%BF%94%E5%9B%9E%E4%B8%ADLong%E7%B1%BB%E5%9E%8B%E7%B2%BE%E5%BA%A6%E4%B8%A2%E5%A4%B1%E9%97%AE%E9%A2%98/" title="配置SpringMvc全局序列化与反序列化，解决Long类型下精度丢失问题（使用FastJson2）"><img class="cover" src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-15/js.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="fas fa-history fa-fw"></i> 2023-06-19</div><div class="title">配置SpringMvc全局序列化与反序列化，解决Long类型下精度丢失问题（使用FastJson2）</div></div></a></div><div><a href="/2023/2/12/SpringBoot%E9%9B%86%E6%88%90Redisson%E6%9B%BF%E6%8D%A2SpringCache%E5%BA%95%E5%B1%82%E5%AE%B9%E5%99%A8%E5%AE%9E%E7%8E%B0/" title="SpringBoot集成Redisson替换SpringCache底层容器实现"><img class="cover" src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-2-26/redisson.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="fas fa-history fa-fw"></i> 2023-02-12</div><div class="title">SpringBoot集成Redisson替换SpringCache底层容器实现</div></div></a></div><div><a href="/2023/2/10/SpringBoot%E9%9B%86%E6%88%90Redisson%E5%AE%9E%E7%8E%B0%E6%B3%A8%E8%A7%A3%E9%99%90%E6%B5%81/" title="SpringBoot集成Redisson实现注解限流"><img class="cover" src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-2-26/redisson.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="fas fa-history fa-fw"></i> 2023-02-12</div><div class="title">SpringBoot集成Redisson实现注解限流</div></div></a></div><div><a href="/2023/1/10/SpringBoot%E9%9B%86%E6%88%90Netty%E5%AE%9E%E7%8E%B0Socket%E9%80%9A%E4%BF%A1/" title="SpringBoot集成Netty实现Socket通信"><img class="cover" src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-2-24/netty.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="fas fa-history fa-fw"></i> 2023-01-10</div><div class="title">SpringBoot集成Netty实现Socket通信</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/common/fei.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Fei</div><div class="author-info__description">当你想起来了，那就记录一点吧</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">24</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">28</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">16</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/tengfei2233"><i class="fab fa-github"></i><span>关注我</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/tengfei2233" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="https://gitee.com/tengfei2233" target="_blank" title="Gitee"><i class="fab fa-git"></i></a><a class="social-icon" href="/youfeige@outlook.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">当你迷茫的时候，那就静下心想想吧！</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#SpringBoot%E9%9B%86%E6%88%90%E6%94%AF%E4%BB%98%E5%AE%9D%E6%B2%99%E7%AE%B1%E6%94%AF%E4%BB%98"><span class="toc-number">1.</span> <span class="toc-text">SpringBoot集成支付宝沙箱支付</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%87%86%E5%A4%87%E6%AD%A5%E9%AA%A4"><span class="toc-number">1.1.</span> <span class="toc-text">准备步骤</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8E%A5%E5%85%A5SpringBoot"><span class="toc-number">1.2.</span> <span class="toc-text">接入SpringBoot</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#SpringBoot%E7%89%88%E6%9C%AC"><span class="toc-number">1.2.1.</span> <span class="toc-text">SpringBoot版本</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BE%9D%E8%B5%96%E7%89%88%E6%9C%AC"><span class="toc-number">1.2.2.</span> <span class="toc-text">依赖版本</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%9C%A8resources%E7%9B%AE%E5%BD%95%E7%BC%96%E5%86%99alipay-properties%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="toc-number">1.2.3.</span> <span class="toc-text">在resources目录编写alipay.properties配置文件</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%BC%96%E5%86%99AlipayConfig-java%E7%94%A8%E4%BA%8E%E8%AF%BB%E5%8F%96%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="toc-number">1.2.4.</span> <span class="toc-text">编写AlipayConfig.java用于读取配置文件</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%9C%A8%E9%9C%80%E8%A6%81%E6%94%AF%E4%BB%98%E7%9A%84%E6%96%B9%E6%B3%95%E4%B8%8A%E8%B0%83%E7%94%A8%E5%A6%82%E4%B8%8B%E6%96%B9%E6%B3%95"><span class="toc-number">1.2.5.</span> <span class="toc-text">在需要支付的方法上调用如下方法</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%BC%82%E6%AD%A5%E5%9B%9E%E8%B0%83"><span class="toc-number">1.2.6.</span> <span class="toc-text">异步回调</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%90%8C%E6%AD%A5%E5%9B%9E%E8%B0%83"><span class="toc-number">1.2.7.</span> <span class="toc-text">同步回调</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BB%A5%E4%B8%8A%E9%85%8D%E7%BD%AE%E5%AE%8C%E5%90%8E%EF%BC%8C%E7%82%B9%E5%87%BB%E6%94%AF%E4%BB%98url%EF%BC%8C%E8%B7%B3%E8%BD%AC%E5%88%B0%E6%94%AF%E4%BB%98%E5%AE%9D%E6%B2%99%E7%AE%B1%E6%89%AB%E7%A0%81%E6%94%AF%E4%BB%98%E9%A1%B5%E9%9D%A2%EF%BC%8C%E4%BD%BF%E7%94%A8%EF%BC%9A%E6%94%AF%E4%BB%98%E5%AE%9D%E6%B2%99%E7%AE%B1%E8%BD%AF%E4%BB%B6%E6%94%AF%E4%BB%98"><span class="toc-number">1.2.8.</span> <span class="toc-text">以上配置完后，点击支付url，跳转到支付宝沙箱扫码支付页面，使用：支付宝沙箱软件支付</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%99%BB%E5%BD%95%E8%B4%A6%E5%8F%B7%E5%AF%86%E7%A0%81%EF%BC%9A"><span class="toc-number">1.2.9.</span> <span class="toc-text">登录账号密码：</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2023/11/21/netty%E7%9A%84%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8%EF%BC%8C%E5%9F%BA%E6%9C%AC%E5%8E%9F%E7%90%86%E5%88%86%E6%9E%90%EF%BC%8C%E7%9B%B8%E5%85%B3%E9%97%AE%E9%A2%98%E8%A7%A3%E5%86%B3-%E6%9B%B4%E6%96%B0%E4%B8%AD/" title="netty的基本使用，基本原理分析，相关问题解(更新中...)"><img src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-11-10/netty-ai.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="netty的基本使用，基本原理分析，相关问题解(更新中...)"/></a><div class="content"><a class="title" href="/2023/11/21/netty%E7%9A%84%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8%EF%BC%8C%E5%9F%BA%E6%9C%AC%E5%8E%9F%E7%90%86%E5%88%86%E6%9E%90%EF%BC%8C%E7%9B%B8%E5%85%B3%E9%97%AE%E9%A2%98%E8%A7%A3%E5%86%B3-%E6%9B%B4%E6%96%B0%E4%B8%AD/" title="netty的基本使用，基本原理分析，相关问题解(更新中...)">netty的基本使用，基本原理分析，相关问题解(更新中...)</a><time datetime="2023-11-21T09:27:51.000Z" title="发表于 2023-11-21 17:27:51">2023-11-21</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/11/10/%E5%9C%A8conda%E7%8E%AF%E5%A2%83%E4%B8%8B%E8%BF%90%E8%A1%8Cstable-diffusion-webui-AI%E7%BB%98%E5%9B%BE/" title="在conda环境下运行stable-diffusion-webui AI绘图"><img src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-11-10/ai.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="在conda环境下运行stable-diffusion-webui AI绘图"/></a><div class="content"><a class="title" href="/2023/11/10/%E5%9C%A8conda%E7%8E%AF%E5%A2%83%E4%B8%8B%E8%BF%90%E8%A1%8Cstable-diffusion-webui-AI%E7%BB%98%E5%9B%BE/" title="在conda环境下运行stable-diffusion-webui AI绘图">在conda环境下运行stable-diffusion-webui AI绘图</a><time datetime="2023-11-10T07:30:51.000Z" title="发表于 2023-11-10 15:30:51">2023-11-10</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/11/10/%E5%9C%A8Ubuntu20%E4%B8%8A%E5%AE%89%E8%A3%85CUDA-cuDNN-Miniconda%E7%8E%AF%E5%A2%83(%E5%85%B6%E5%AE%83%E7%B3%BB%E7%BB%9F%E5%90%8C%E7%90%86)/" title="在Ubuntu20上安装CUDA+cuDNN+Miniconda环境(其它系统同理)"><img src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-11-10/ai.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="在Ubuntu20上安装CUDA+cuDNN+Miniconda环境(其它系统同理)"/></a><div class="content"><a class="title" href="/2023/11/10/%E5%9C%A8Ubuntu20%E4%B8%8A%E5%AE%89%E8%A3%85CUDA-cuDNN-Miniconda%E7%8E%AF%E5%A2%83(%E5%85%B6%E5%AE%83%E7%B3%BB%E7%BB%9F%E5%90%8C%E7%90%86)/" title="在Ubuntu20上安装CUDA+cuDNN+Miniconda环境(其它系统同理)">在Ubuntu20上安装CUDA+cuDNN+Miniconda环境(其它系统同理)</a><time datetime="2023-11-10T07:27:51.000Z" title="发表于 2023-11-10 15:27:51">2023-11-10</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/8/27/Docker-Compose%E5%AD%A6%E4%B9%A0/" title="Docker Compose学习"><img src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-26/docker.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Docker Compose学习"/></a><div class="content"><a class="title" href="/2023/8/27/Docker-Compose%E5%AD%A6%E4%B9%A0/" title="Docker Compose学习">Docker Compose学习</a><time datetime="2023-08-27T15:34:50.000Z" title="发表于 2023-08-27 23:34:50">2023-08-27</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/8/27/Dockerfile%E5%AD%A6%E4%B9%A0/" title="Dockerfile学习"><img src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-26/docker.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Dockerfile学习"/></a><div class="content"><a class="title" href="/2023/8/27/Dockerfile%E5%AD%A6%E4%B9%A0/" title="Dockerfile学习">Dockerfile学习</a><time datetime="2023-08-27T15:34:37.000Z" title="发表于 2023-08-27 23:34:37">2023-08-27</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-3-2/alipay.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2022 - 2024 By Fei</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">欢迎进入<a href="tengfei2233.gitee.io/">飞の博客</a>!</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="https://cdn.staticfile.org/hexo-theme-butterfly/4.7.0/js/utils.min.js"></script><script src="https://cdn.staticfile.org/hexo-theme-butterfly/4.7.0/js/main.min.js"></script><script src="https://cdn.staticfile.org/hexo-theme-butterfly/4.7.0/js/tw_cn.min.js"></script><script src="https://cdn.staticfile.org/fancyapps-ui/4.0.31/fancybox.umd.min.js"></script><script src="https://cdn.staticfile.org/instant.page/5.1.1/instantpage.min.js" type="module"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.staticfile.org/pangu/4.0.7/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (false){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><div class="js-pjax"><script>function loadValine () {
  function initValine () {
    const valine = new Valine(Object.assign({
      el: '#vcomment',
      appId: '0kbeJfFlvhvkYfqMqwwVCx1a-gzGzoHsz',
      appKey: 'rziWUw1MTHMW7d9eeCQzu9HV',
      avatar: 'monsterid',
      serverURLs: '',
      emojiMaps: "",
      path: window.location.pathname,
      visitor: false
    }, null))
  }

  if (typeof Valine === 'function') initValine() 
  else getScript('https://cdn.staticfile.org/valine/1.5.1/Valine.min.js').then(initValine)
}

if ('Valine' === 'Valine' || !true) {
  if (true) btf.loadComment(document.getElementById('vcomment'),loadValine)
  else setTimeout(loadValine, 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script></div><script defer="defer" id="ribbon" src="https://cdn.staticfile.org/butterfly-extsrc/1.1.3/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="true"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div><script src="https://cdn.staticfile.org/hexo-theme-butterfly/4.7.0/js/search/local-search.min.js"></script></div></body></html>